<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

// 用户相关API
Route::prefix('user')->group(function () {
    // 微信授权获取用户信息
    Route::post('/get-user', 'App\Http\Controllers\Api\UserController@getUser');
    // 发送短信验证码
    Route::post('/send-sms', 'App\Http\Controllers\Api\UserController@sendSms');
    // 验证短信验证码
    Route::post('/validate-code', 'App\Http\Controllers\Api\UserController@validateCode');
    // 检查手机号是否已绑定
    Route::post('/check-mobile-exists', 'App\Http\Controllers\Api\UserController@checkMobileExists');
    // 用户登录
    Route::post('/login', 'App\Http\Controllers\Api\UserController@login');
});

// 图片处理相关API
Route::prefix('image')->group(function () {
    // 批量生成缩略图
    Route::post('/generate-thumbnails', 'App\Http\Controllers\Api\ImageController@generateThumbnails');
    
    // 异步批量生成缩略图（队列方式）
    Route::get('/generate-thumbnails-async', 'App\Http\Controllers\Api\ImageController@generateThumbnailsAsync');
    
    // 获取缩略图生成进度
    Route::get('/progress', 'App\Http\Controllers\Api\ImageController@getProgress');
    
    // 清理缩略图目录
    Route::delete('/clean-thumbnails', 'App\Http\Controllers\Api\ImageController@cleanThumbnails');
    
    // 重新生成指定文件的缩略图
    Route::post('/regenerate-single', 'App\Http\Controllers\Api\ImageController@regenerateSingle');
    
    // 继续生成剩余的缩略图
    Route::get('/continue-remaining', 'App\Http\Controllers\Api\ImageController@continueRemainingThumbnails');
    
    // 获取有问题的文件列表
    Route::get('/problem-files', 'App\Http\Controllers\Api\ImageController@getProblemFiles');
    
    // 通用：批量生成指定目录的缩略图
    Route::post('/generate-directory-thumbnails', 'App\Http\Controllers\Api\ImageController@generateDirectoryThumbnails');
    
    // 商家入驻：批量生成缩略图（同步）
    Route::post('/generate-store-thumbnails', 'App\Http\Controllers\Api\ImageController@generateStoreThumbnails');
    
    // 商家入驻：异步批量生成缩略图（队列方式）
    Route::get('/generate-store-thumbnails-async', 'App\Http\Controllers\Api\ImageController@generateStoreThumbnailsAsync');
});

// 认证相关API
Route::prefix('auth')->group(function () {
    // 微信公众号H5授权登录
    Route::post('/wechat-h5-login', 'App\Http\Controllers\Api\AuthApiController@wechatH5Login');
    
    // 微信小程序登录
    Route::post('/wechat-login', 'App\Http\Controllers\Api\AuthApiController@wechatLogin');
    
    // 发送手机验证码
    Route::post('/send-sms-code', 'App\Http\Controllers\Api\AuthApiController@sendSmsCode');
    
    // 绑定手机号
    Route::post('/bind-phone', 'App\Http\Controllers\Api\AuthApiController@bindPhone');
    
    // 手机号登录
    Route::post('/phone-login', 'App\Http\Controllers\Api\AuthApiController@phoneLogin');
    
    // 刷新token
    Route::post('/refresh-token', 'App\Http\Controllers\Api\AuthApiController@refreshToken');
    
    // 退出登录
    Route::post('/logout', 'App\Http\Controllers\Api\AuthApiController@logout');
});

// 商家相关API
Route::prefix('merchants')->group(function () {
    // 获取商家列表
    Route::post('/', 'App\Http\Controllers\Api\MerchantApiController@index');
    
    // 获取商家详情
    Route::post('/detail', 'App\Http\Controllers\Api\MerchantApiController@detail');
    
    // 获取商家分类
    Route::post('/categories', 'App\Http\Controllers\Api\MerchantApiController@categories');
    
    // 搜索商家
    Route::post('/search', 'App\Http\Controllers\Api\MerchantApiController@search');
    
    // 获取置换支持类型
    Route::post('/swap-types', 'App\Http\Controllers\Api\MerchantApiController@swapTypes');
});

// 商家入驻API
Route::prefix('merchant-onboarding')->group(function () {
    // 提交入驻申请
    Route::post('/apply', 'App\Http\Controllers\Api\MerchantOnboardingApiController@apply');
    
    // 查询申请状态
    Route::post('/status', 'App\Http\Controllers\Api\MerchantOnboardingApiController@status');
    
    // 获取入驻协议
    Route::post('/agreement', 'App\Http\Controllers\Api\MerchantOnboardingApiController@agreement');
    
    // 获取商家分类选项
    Route::post('/categories', 'App\Http\Controllers\Api\MerchantOnboardingApiController@categories');
});

// 自提点API
Route::prefix('pickup-points')->group(function () {
    // 获取自提点列表
    Route::post('/', 'App\Http\Controllers\Api\PickupPointApiController@index');
    
    // 获取自提点详情
    Route::post('/detail', 'App\Http\Controllers\Api\PickupPointApiController@show');
    
    // 搜索附近的自提点
    Route::post('/nearby/search', 'App\Http\Controllers\Api\PickupPointApiController@nearby');
    
    // 提交自提点申请
    Route::post('/apply', 'App\Http\Controllers\Api\PickupPointApiController@apply');
});

// 用户中心API
Route::prefix('user-center')->group(function () {
    // 获取用户信息
    Route::post('/profile', 'App\Http\Controllers\Api\UserCenterApiController@profile');
    
    // 获取钱包信息
    Route::post('/wallet', 'App\Http\Controllers\Api\UserCenterApiController@wallet');
    
    // 获取云仓信息
    Route::post('/cloud-storage', 'App\Http\Controllers\Api\UserCenterApiController@cloudStorage');
    
    // 获取商家管理菜单
    Route::post('/merchant-menu', 'App\Http\Controllers\Api\UserCenterApiController@merchantMenu');
    
    // 获取门店管理菜单
    Route::post('/store-menu', 'App\Http\Controllers\Api\UserCenterApiController@storeMenu');
    
    // 获取实用工具
    Route::post('/tools', 'App\Http\Controllers\Api\UserCenterApiController@tools');
});

// 授信相关API
Route::prefix('credit')->group(function () {
    Route::post('/dashboard', 'App\Http\Controllers\Api\CreditController@dashboard');
    Route::post('/status', 'App\Http\Controllers\Api\CreditController@activationStatus');
    Route::post('/activate', 'App\Http\Controllers\Api\CreditController@activate');
    Route::post('/cancel', 'App\Http\Controllers\Api\CreditController@cancel');
    Route::post('/warehouse/summary', 'App\Http\Controllers\Api\CreditController@warehouseSummary');
    Route::post('/warehouse/flows', 'App\Http\Controllers\Api\CreditController@warehouseFlows');
    Route::post('/warehouse/member-search', 'App\Http\Controllers\Api\CreditController@searchTransferMembers');
    Route::post('/warehouse/transfer', 'App\Http\Controllers\Api\CreditController@transfer');
    Route::post('/warehouse/repay', 'App\Http\Controllers\Api\CreditController@repay');
    Route::post('/review', 'App\Http\Controllers\Api\CreditController@review');
});

// 同城服务API
Route::prefix('samecity')->group(function () {
    // Banner图相关
    Route::post('/banners', 'App\Http\Controllers\Api\SameCityController@banners');
    
    // 商品相关
    Route::post('/hot-products', 'App\Http\Controllers\Api\SameCityController@hotProducts');
    Route::post('/new-products', 'App\Http\Controllers\Api\SameCityController@newProducts');
    Route::post('/recommend-products', 'App\Http\Controllers\Api\SameCityController@recommendProducts');
    
    // 商家相关
    Route::post('/nearby-stores', 'App\Http\Controllers\Api\SameCityController@nearbyStores');
    Route::post('/recommend-stores', 'App\Http\Controllers\Api\SameCityController@recommendStores');
    Route::post('/new-stores', 'App\Http\Controllers\Api\SameCityController@newStores');
});

// 地址API
Route::prefix('address')->group(function () {
    Route::post('/get-data', 'App\Http\Controllers\Api\AddressController@getAddressData');
});

// 商家认证API
Route::prefix('merchant')->group(function () {
    // 商家登录
    Route::post('/login', 'App\Http\Controllers\Api\MerchantAuthController@login');
    
    // 需要认证的商家接口
    Route::middleware(['auth:api'])->group(function () {
        Route::post('/profile', 'App\Http\Controllers\Api\MerchantAuthController@profile');
        Route::post('/today-stats', 'App\Http\Controllers\Api\MerchantAuthController@todayStats');
    });
});

// 门店申请API
Route::prefix('store')->group(function () {
    // 提交门店申请
    Route::post('/apply', 'App\Http\Controllers\Api\StoreController@apply');
    
    // 检查是否可以申请门店
    Route::post('/verify-apply', 'App\Http\Controllers\Api\StoreController@verifyApply');
    
    // 获取门店申请状态
    Route::post('/verify-apply-status', 'App\Http\Controllers\Api\StoreController@verifyApplyStatus');
    
    // 获取门店申请信息
    Route::post('/get-store-apply', 'App\Http\Controllers\Api\StoreController@getStoreApply');
    
    // 获取门店信息
    Route::post('/get-store-info', 'App\Http\Controllers\Api\StoreController@getStoreInfo');
    
    // 获取供应商清单
    Route::post('/get-vendor-list', 'App\Http\Controllers\Api\StoreController@getVendorList');
    
    // 文件上传
    Route::post('/upload', 'App\Http\Controllers\Api\StoreController@upload');
    
    // 获取门店分类列表
    Route::post('/categories', 'App\Http\Controllers\Api\StoreController@getStoreCategorys');
    
    // 获取自提点申请状态
    Route::post('/pickup-point-status', 'App\Http\Controllers\Api\StoreController@pickupPointStatus');
    
    // 提交自提点申请
    Route::post('/pickup-point-submit', 'App\Http\Controllers\Api\StoreController@pickupPointSubmit');
    
    // 重新提交自提点申请
    Route::post('/pickup-point-resubmit', 'App\Http\Controllers\Api\StoreController@pickupPointResubmit');
    // 从副本合并：获取会员信息
    Route::post('/member-info', 'App\Http\Controllers\Api\StoreController@getMemberInfo');
});

// 商品查询API
Route::prefix('goods')->group(function () {
    // 获取分类列表
    Route::post('/categories', 'App\Http\Controllers\Api\GoodsController@getCategories');
    // 搜索商品
    Route::post('/search', 'App\Http\Controllers\Api\GoodsController@searchGoods');
    // 获取商品详情（新表结构）
    Route::post('/detail', 'App\Http\Controllers\Api\GoodsApiController@detail');
    // 获取商品列表（新表结构）
    Route::post('/list', 'App\Http\Controllers\Api\GoodsApiController@list');
});

// 审核相关API
Route::prefix('verification')->group(function () {
    // 获取提货信息详情
    Route::post('/detail', 'App\Http\Controllers\Api\VerificationController@detail');
    // 确认核销
    Route::post('/confirm', 'App\Http\Controllers\Api\VerificationController@confirm');
    
    // 员工授权相关接口
    // 获取员工授权列表
    Route::post('/staff-list', 'App\Http\Controllers\Api\VerificationController@staffList');
    // 新增员工授权
    Route::post('/staff-add', 'App\Http\Controllers\Api\VerificationController@staffAdd');
    // 取消员工授权
    Route::post('/staff-cancel', 'App\Http\Controllers\Api\VerificationController@staffCancel');
    // 删除员工授权记录
    Route::post('/staff-delete', 'App\Http\Controllers\Api\VerificationController@staffDelete');
    // 通过UID查询员工信息
    Route::post('/staff-info', 'App\Http\Controllers\Api\VerificationController@staffInfo');
    // 从副本合并：获取核销记录列表
    Route::post('/verification-records', 'App\Http\Controllers\Api\VerificationController@verificationRecords');
    // 获取门店收款码（置换码）
    Route::post('/get-collection-code', 'App\Http\Controllers\Api\VerificationController@getCollectionCode');
});

// 用户API
Route::prefix('user')->group(function () {
    
    // 获取用户信息
    Route::get('/get-user', 'App\Http\Controllers\Api\UserController@getUser')->name('http.api.user.get-user');

    // 核销用户自提
    Route::get('/verifiy', 'App\Http\Controllers\Api\UserController@verifiy')->name('http.api.user.verifiy');
});

// 从副本合并：微信相关API
Route::prefix('wechat')->group(function () {
    // 获取微信JS-SDK配置
    Route::get('/config', 'App\Http\Controllers\H5Controller@getWechatConfig');
    // 微信授权回调
    Route::get('/callback', 'App\Http\Controllers\H5Controller@wechatCallback');
});


// 支付相关API
Route::prefix('payment')->group(function () {
    // 根据平台代码获取平台配置信息
    Route::post('/get-platform-code', 'App\Http\Controllers\Api\PaymentApiController@getPlatformCode');
    
    // 验证平台代码是否有效
    Route::post('/validate-platform-code', 'App\Http\Controllers\Api\PaymentApiController@validatePlatformCode');
    
    // 获取支付平台列表
    Route::post('/platform-list', 'App\Http\Controllers\Api\PaymentApiController@getPlatformList');
    
    // 获取支付设置
    Route::post('/get-pay-set', 'App\Http\Controllers\Api\PaymentApiController@getPaySet');
    
    // 根据代码获取关联信息
    Route::post('/get-relation-by-code', 'App\Http\Controllers\Api\PaymentApiController@getRelationByCode');
    
    // 商品购买
    Route::post('/goods-buy', 'App\Http\Controllers\Api\PaymentApiController@goodsBuy');
    
    // 获取支付列表
    Route::post('/payment-list', 'App\Http\Controllers\Api\PaymentApiController@paymentList');
    
    // 置换类型列表
    Route::post('/swap-types', 'App\Http\Controllers\Api\PaymentApiController@swapTypes');
    
    // 创建订单
    Route::post('/create-order', 'App\Http\Controllers\Api\PaymentApiController@createOrder');
    
    // 支付订单
    Route::post('/pay-order', 'App\Http\Controllers\Api\PaymentApiController@payOrder');
    
    // 合并支付获取信息
    Route::post('/merge-pay', 'App\Http\Controllers\Api\PaymentApiController@mergePay');
    
    // 余额支付
    Route::post('/credit-merge-pay', 'App\Http\Controllers\Api\PaymentApiController@creditMergePay');
    
    // 语音播报
    Route::post('/voice-index', 'App\Http\Controllers\Api\PaymentApiController@voiceIndex');
    
    // 获取语音播报设置
    Route::post('/get-voice-set', 'App\Http\Controllers\Api\PaymentApiController@getVoiceSet');
    
    // 【临时接口】创建门店置换配置
    Route::post('/create-store-swap-config', 'App\Http\Controllers\Api\PaymentApiController@createStoreSwapConfig');
    
    // 【临时接口】充值沐浴露余额
    Route::post('/recharge-breed-coin', 'App\Http\Controllers\Api\PaymentApiController@rechargeBreedCoin');
    Route::post('/user-balances', [\App\Http\Controllers\Api\PaymentApiController::class, 'getUserBalances']);
    // 【临时接口】充值茶包余额
    Route::post('/recharge-teabag', 'App\Http\Controllers\Api\PaymentApiController@rechargeTeaBag');
});

// 微信相关接口
Route::prefix('wechat')->group(function () {
    // 获取微信JS-SDK签名
    Route::get('/js-sdk-signature', 'App\Http\Controllers\WechatVerifyController@getJsSdkSignature');
    
    // 微信服务器验证
    Route::get('/verify', 'App\Http\Controllers\WechatVerifyController@verify');
    Route::post('/verify', 'App\Http\Controllers\WechatVerifyController@handleMessage');
});


// 门店相关API
Route::prefix('store')->group(function () {
    // 门店登录
    Route::post('/storeLogin/login', 'App\Http\Controllers\Api\store\StoreLoginController@login');
    
    // 门店订单相关
    Route::prefix('order')->group(function () {
        // 订单列表
        Route::post('/list', 'App\Http\Controllers\Api\store\StoreOrderController@index');
        // 订单详情
        Route::post('/detail', 'App\Http\Controllers\Api\store\StoreOrderController@detail');
        // 收银台订单列表
        Route::post('/cashier-order-list', 'App\Http\Controllers\Api\store\StoreOrderController@cashierOrderList');
        // 收银台订单详情
        Route::post('/cashier-order-detail', 'App\Http\Controllers\Api\store\StoreOrderController@cashierOrderDetail');
        // 关闭订单
        Route::post('/close-order', 'App\Http\Controllers\Api\store\StoreOrderController@closeOrder');
        // 获取订单状态列表
        Route::post('/status-list', 'App\Http\Controllers\Api\store\StoreOrderController@getOrderStatus');
        // 获取支付方式列表
        Route::post('/payment-methods', 'App\Http\Controllers\Api\store\StoreOrderController@getPaymentMethods');
    });
    
    // 门店商品相关
    Route::prefix('goods')->group(function () {
        // 商品列表
        Route::post('/index', 'App\Http\Controllers\Api\store\GoodsController@index');
        // 商品详情
        Route::post('/detail', 'App\Http\Controllers\Api\store\GoodsController@detail');
        // 创建商品
        Route::post('/create', 'App\Http\Controllers\Api\store\GoodsController@create');
        // 更新商品
        Route::post('/update', 'App\Http\Controllers\Api\store\GoodsController@update');
        // 删除商品
        Route::post('/delete', 'App\Http\Controllers\Api\store\GoodsController@delete');
        // 批量更新商品
        Route::post('/batchUpdate', 'App\Http\Controllers\Api\store\GoodsController@batchUpdate');
        // 获取分类列表
        Route::post('/getCategories', 'App\Http\Controllers\Api\store\GoodsController@getCategories');
        // 获取品牌列表
        Route::post('/getBrands', 'App\Http\Controllers\Api\store\GoodsController@getBrands');
        
        // 商品分类管理
        // 创建分类
        Route::post('/createCategory', 'App\Http\Controllers\Api\store\GoodsController@createCategory');
        // 更新分类
        Route::post('/updateCategory', 'App\Http\Controllers\Api\store\GoodsController@updateCategory');
        // 删除分类
        Route::post('/deleteCategory', 'App\Http\Controllers\Api\store\GoodsController@deleteCategory');
        // 获取分类详情
        Route::post('/getCategory', 'App\Http\Controllers\Api\store\GoodsController@getCategory');
        // 更新分类显示状态
        Route::post('/updateCategoryShowStatus', 'App\Http\Controllers\Api\store\GoodsController@updateCategoryShowStatus');
        // 更新分类导航状态
        Route::post('/updateCategoryNavStatus', 'App\Http\Controllers\Api\store\GoodsController@updateCategoryNavStatus');
        // 获取带子分类的分类列表
        Route::post('/getCategoriesWithChildren', 'App\Http\Controllers\Api\store\GoodsController@getCategoriesWithChildren');
    });
    
    // 门店文件上传相关
    Route::prefix('upload')->group(function () {
        // 图片上传
        Route::post('/image', 'App\Http\Controllers\Api\store\UploadController@image');
        // 文件上传
        Route::post('/file', 'App\Http\Controllers\Api\store\UploadController@file');
        // 批量上传
        Route::post('/batch', 'App\Http\Controllers\Api\store\UploadController@batch');
        // 删除文件
        Route::post('/delete', 'App\Http\Controllers\Api\store\UploadController@delete');
    });

        // 商品订单相关
        Route::prefix('goods-order')->group(function () {
            // 商品订单列表
            Route::post('/list', 'App\Http\Controllers\Api\store\GoodsOrderController@getList');
            // 商品订单详情
            Route::post('/detail', 'App\Http\Controllers\Api\store\GoodsOrderController@getDetail');
            // 关闭商品订单
            Route::post('/close-order', 'App\Http\Controllers\Api\store\GoodsOrderController@closeOrder');
            // 获取商品订单状态列表
            Route::post('/status-list', 'App\Http\Controllers\Api\store\GoodsOrderController@getStatusList');
            // 获取商品订单支付方式列表
            Route::post('/payment-methods', 'App\Http\Controllers\Api\store\GoodsOrderController@getPaymentMethods');
        });
});

// 支付相关API（新版）
Route::prefix('payment')->group(function () {
    // 获取用户余额（茶包和沐浴露）- 新接口
    Route::post('/get-user-balances', 'App\Http\Controllers\Api\UserBalanceController@getUserBalances');
});

//前端相关API
Route::prefix('frontend')->group(function () {
    //订单相关API
    Route::prefix('order')->group(function () {
        //订单数量统计
        Route::post('/counts', 'App\Http\Controllers\Api\frontend\OrderController@counts');
        //订单列表
        Route::post('/list', 'App\Http\Controllers\Api\frontend\OrderController@list');
        //订单详情
        Route::post('/detail', 'App\Http\Controllers\Api\frontend\OrderController@detail');
        //订单核销详情（用于核销页面）
        Route::post('/verification-detail', 'App\Http\Controllers\Api\frontend\OrderController@verificationDetail');
        //下单
        Route::post('/index', 'App\Http\Controllers\Api\frontend\OrderController@index');
        //支付
        Route::post('/credit', 'App\Http\Controllers\Api\frontend\OrderController@credit');
        //提货核销
        Route::post('/verifiy', 'App\Http\Controllers\Api\frontend\OrderController@verifiy');
    });
});